//import org.apache.logging.log4j.Level;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
//import org.apache.logging.log4j.core.*;
//import org.apache.logging.log4j.core.appender.RollingFileAppender;
//import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
//import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
//import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
//import org.apache.logging.log4j.core.appender.rolling.action.IfLastModified;
//import org.apache.logging.log4j.core.config.AppenderRef;
//import org.apache.logging.log4j.core.config.Configuration;
//import org.apache.logging.log4j.core.config.Configurator;
//import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
//import org.apache.logging.log4j.core.layout.PatternLayout;
//
//import java.nio.file.Path;
//import java.nio.file.Paths;
//
//public class Log4j2RollingFileConfig {
//
//    private static final Logger logger = LogManager.getLogger(Log4j2RollingFileConfig.class);
//
//    public static void main(String[] args) {
//        /**
//         *  <RollingFile name="rollingFile"
//         *                      fileName="${logDir}/rollLog.log"
//         *                      filePattern="${logDir}/%d{yyyy-MM-dd}/rollLog-%d{yyyy-MM-dd}-%i.log.zip">
//         *             <PatternLayout pattern="${patternLayout}"/>
//         *             <Policies>
//         *                 <OnStartupTriggeringPolicy/>
//         *                 <TimeBasedTriggeringPolicy/>
//         *                 <SizeBasedTriggeringPolicy size="10GB"/>
//         *             </Policies>
//         *             <DefaultRolloverStrategy max="10">
//         *                 <Delete basePath="${logDir}" maxDepth="2">
//         *                     <IfLastModified age="180d"/>
//         *                 </Delete>
//         *                 <Delete basePath="${logDir}" maxDepth="1">
//         *                     <IfLastModified age="180d"/>
//         *                 </Delete>
//         *             </DefaultRolloverStrategy>
//         *         </RollingFile>
//         */
//
//        Configurator.setLevel(loggerName, Level.toLevel(level));
//
//        // 创建配置对象
//        Configuration configuration = new XmlConfiguration();
//
//        // 设置日志文件路径变量
//        String logDir = "/path/to/your/log/dir"; // 请替换为你的日志目录路径
//        String patternLayout = "%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"; // 自定义日志格式
//
//        // 创建RollingFileAppender
//        RollingFileAppender rollingFileAppender = RollingFileAppender.newBuilder()
//                .setName("rollingFile")
//                .withFileName(logDir + "/rollLog.log")
//                .withFilePattern(logDir + "/%d{yyyy-MM-dd}/rollLog-%d{yyyy-MM-dd}-%i.log.zip")
//                .withPolicy(TimeBasedTriggeringPolicy.createPolicy("1", "true", null, null))
//                .withPolicy(SizeBasedTriggeringPolicy.createPolicy("10GB"))
//                .withStrategy(DefaultRolloverStrategy.createStrategy()
//                        .withMax(10)
//                        .addDelete(
//                                Delete.defaultDelete()
//                                        .withIfLastModified(IfLastModified.of("180d"))
//                                        .withBasePath(Paths.get(logDir))
//                                        .withMaxDepth(2))
//                        .addDelete(
//                                Delete.defaultDelete()
//                                        .withIfLastModified(IfLastModified.of("180d"))
//                                        .withBasePath(Paths.get(logDir))
//                                        .withMaxDepth(1))
//                )
//                .build();
//
//        // 设置PatternLayout
//        rollingFileAppender.setLayout(PatternLayout.newBuilder()
//                .withPattern(patternLayout)
//                .build());
//
//        // 将Appender添加到Logger配置中
//        configuration.addAppender(rollingFileAppender);
//        Configurator.setLevel("root", Level.ALL);
//        Configurator.setRootLevel(Level.ALL);
//
//        Configurator.initialize(configuration);
//        // 测试日志输出
//        logger.info("This is an info message.");
//    }
//}